home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14304 < prev    next >
Encoding:
Text File  |  1996-08-05  |  3.3 KB  |  89 lines

  1. Path: news.informatik.uni-muenchen.de!usenet
  2. From: Kurt Watzka <watzka@stat.uni-muenchen.de>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: #including everything
  5. Date: Fri, 12 Apr 1996 19:48:04 +0200
  6. Organization: Institut fⁿr Statistik
  7. Message-ID: <316E9754.237@stat.uni-muenchen.de>
  8. References: <829297481snz@setch.demon.co.uk>
  9. NNTP-Posting-Host: pc4.stat.uni-muenchen.de
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (WinNT; I)
  14.  
  15. Mark Setchell wrote:
  16. > Does anyone have an opinion about how sensible it is to #include all
  17. > standard system header files in C programs? I work on a project with
  18. > approximately 2000 files and 500,000 lines of code and every file
  19. > has a long piece at the start like this:
  20. > #include <stdio.h>
  21. > #include <errno.h>
  22. > #if !defined(SGI) && !defined(HPUX)
  23. > #include <x.h>
  24. > #else
  25. > #if !defined(IBM_R2) && !defined(CRAY)
  26. > #include <y.h>
  27. > #endif
  28. > #endif
  29. > This is obviously a maintenance nightmare, porting is no fun either. I
  30. > am thinking of making a single include file with all system headers in
  31. > it (i.e. ones in <> as opposed to those in "").
  32.  
  33. A reasonable approach if all your compilation units use all "system" header
  34. files, _but_ this is the main reason for this problem, anyway.
  35.  
  36. Portable programs can be designed so that system specific stuff happens 
  37. in system specific compilation units, whereas portable stuff happens in
  38. potable compilation units. 
  39.  
  40. A compilation unit designed for POSIX directory access can use <unistd.h>
  41. without a bad conscience, whereas the implementation of a general purpose
  42. "key to value" map can use "standard" header files without any need to
  43. access system specific headers, because it simply does not need the 
  44. additional features provided by them.
  45.  
  46. The "long list of headers at the beginning of each file"-problem usually
  47. is a result of a bad modularization. In most cases, you should not need
  48. that long list of "system" headers.
  49.  
  50. > I suspect the disadvantages are:
  51. > 1) If it changes, all files have to be rebuilt - but that's ok it won't
  52. >    change often
  53. > 2) It may bloat the size of the binaries by including unused variables,
  54. >    but that's not really a problem on Virtual Memory machines, and the
  55. >    increase in size isn't much anyway.
  56.  
  57. If you _define_ variables in a header file, you do have a problem, and the
  58. problem is not increasing code size when the header is included in
  59. numerous compilation units.
  60.  
  61. Including all possible header files might add some symbol information to 
  62. your executable, but the additional size should not survive "strip" or a 
  63. "release build".
  64.  
  65. > 3) ???
  66. > Weighed against this, the advantages are:
  67. > 1) porting and maintenance become easier with only one file to maintain
  68.  
  69. I stronly disagree with this. There may be some "services" that have
  70. to include a system specific header file in the header file that provides
  71. the interface to that "service", but in general, non-portable includes
  72. should happen in non-portable compilation units. 
  73.  
  74. > 2) all system calls/functions are guaranteed to be prototyped
  75.  
  76. If your compiler does not support "forcing" prototypes for functions,
  77. you should think about changing your tool.
  78.  
  79. > Also, which system files should I #include?
  80.  
  81. In each compilation unit, the files needed by that compilation unit and
  82. no others.
  83.  
  84. Kurt
  85.